<template>
  <a-card :bordered="false">
    <!--********************** 查询区域 **********************-->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="12">
            <a-form-item label="司机姓名">
              <a-input placeholder="请输入司机姓名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item label="货运专线">
              <a-input placeholder="请输入司机货运专线"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="8" :sm="12">
              <a-form-item label="司机手机号">
                <a-input placeholder="请输入司机手机号"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item label="紧急联系人姓名">
                <a-input placeholder="请输入紧急联系人姓名"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item label="紧急联系人电话">
                <a-input placeholder="请输入紧急联系人电话"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="8" :sm="12">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!--********************** table清空区域 **********************-->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <!--table的操作部分-->
        <span slot="action" slot-scope="text, record">
          <a @click="dataShow(record)">更多</a>
          <a-divider type="vertical"/>
          <a @click="stateShow(record)">权限</a>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>
  import { JeecgListNoTimeMixin } from '@/mixins/JeecgListNoTimeMixin'
  import { deleteAction, getAction, downFile } from '@/api/manage'

  export default {
    name: 'SjGl',
    mixins: [JeecgListNoTimeMixin],
    data() {
      return {
        description: '司机管理页面',
        // 表头
        columns: [
          {
            title: '司机姓名',
            align: 'center',
            dataIndex: 'sjXm'
          },
          {
            title: '司机手机号',
            align: 'center',
            dataIndex: 'sjSjh'
          },{
            title: '货物专线',
            align: 'center',
            dataIndex: 'sjHwzx',
            sorter: (a, b) => a.sjHwzx- b.sjHwzx
          }, {
            title: '接单状态',
            align: 'center',
            dataIndex: 'sjJdzt',
            filters: [{
              text: '空闲',
              value: '0'
            }, {
              text: '忙碌',
              value: '1'
            }],
            filterMultiple: false,
            sorter: (a, b) => a.sjJdzt- b.sjJdzt
          },
          {
            title: '注册时间',
            align: 'center',
            dataIndex: 'sjTime',
            sorter: (a, b) => a.sjTime- b.sjTime
          },{
            title: '会员',
            dataIndex: 'state',
            align: 'center',
            filters: [{
              text: '否',
              value: '0'
            }, {
              text: '是',
              value: '1'
            }],
            filterMultiple: false,
            onFilter: (value, record) => record.address.indexOf(value) === 0,
            sorter: (a, b) => a.state.length - b.state.length
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/my/sjUser/list',
          getOneUserAllData: '/my/sjInfo/getOneSjInfo?sjBh='
        },
        //数据与权限弹窗
        dataVisible: false,
        stateVisible: false,
        //选中的司机的信息
        chooseShowUser: null,
        chooseShowUserAllData: null,
        //权限控制的多选
        stateOptions: ['Apple', 'Pear', 'Orange'],
        defaultCheckedList: ['Orange'],
        indeterminate: true,
        checkAll: false,
        /* table加载状态 */
        loading: false
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      dataShow: function(record) {
        console.log('数据选中司机为：' + record.sjBh + '   ' + record.sjNc)
        if (this.chooseShowUser !== record) {
          this.chooseShowUser = record
          this.loading = true
          getAction(this.url.getOneUserAllData + this.chooseShowUser.sjBh).then((res) => {
            console.log(res.success)
            console.log(res)
            if (res.success) {
              this.chooseShowUserAllData = res.result
              console.log(this.chooseShowUserAllData)
              //初始化数据
            }
            if (res.code === 510) {
              this.$message.warning(res.message)
            }
            this.loading = false
          })
        }
        this.dataVisible = true
      },
      stateShow: function(record) {
        console.log('权限选中司机为：' + record.sjBh + '   ' + record.sjNc)
        console.log('------------------- open先输出一波 ------------------')
        console.log(this.chooseShowUser)
        console.log(this.chooseShowUserAllData)
        console.log('------------------- edn先输出一波 ------------------')
        if (this.chooseShowUser !== record) {
          this.chooseShowUser = record
          this.loading = true
          getAction(this.url.getOneUserAllData + this.chooseShowUser.sjBh).then((res) => {
            console.log(res.success)
            console.log(res)
            if (res.success) {
              this.chooseShowUserAllData = res.result
              console.log(this.chooseShowUserAllData)
              //得到当前的权限数组
            }
            if (res.code === 510) {
              this.$message.warning(res.message)
            }
            this.loading = false
          })
        } else {
          //得到当前的权限数组
        }
        this.stateVisible = true
      },
      onChange() {
        this.indeterminate = !!this.defaultCheckedList.length && (this.defaultCheckedList.length < this.stateOptions.length)
        this.checkAll = this.defaultCheckedList.length === this.stateOptions.length
      },
      onCheckAllChange(e) {
        Object.assign(this, {
          checkedList: e.target.checked ? this.stateOptions : [],
          indeterminate: false,
          checkAll: e.target.checked
        })
      },
      handleCancel() {
        this.dataVisible = false
        this.stateVisible = false
      },
      submitData() {
        this.dataVisible = false
        this.stateVisible = false
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>